package com.fourierlab.ibator.plugins;

import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.ibator.api.dom.OutputUtilities;

public class Document extends org.apache.ibatis.ibator.api.dom.xml.Document {

	public Document() {
		this("", "");
	}
	
	public Document(String publicId, String systemId) {
		super(publicId, systemId);
	}

	/* (non-Javadoc)
	 * @see org.apache.ibatis.ibator.api.dom.xml.Document#getFormattedContent()
	 */
	@Override
	public String getFormattedContent() {
        StringBuilder sb = new StringBuilder();
        
        sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");

        OutputUtilities.newLine(sb);
        if (StringUtils.isEmpty(getPublicId()) && StringUtils.isEmpty(getSystemId())) {
        } else {
        	sb.append("<!DOCTYPE ");
        	sb.append(getRootElement().getName());
        	sb.append(" PUBLIC \"");
        	sb.append(getPublicId());
        	sb.append("\" \"");
        	sb.append(getSystemId());
        	sb.append("\" >");
        }
        
        OutputUtilities.newLine(sb);
        sb.append(getRootElement().getFormattedContent(0));
        
        return sb.toString();
	}
}
